﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    public partial class StateMachineMetadata : AbsMetaDataContent
    {
        /// <summary>
        /// 主键id
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// 状态机标识
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 状态机名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 状态机描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 所属CDO.ID
        /// </summary>
        public string CDOMetadataID { get; set; }

        /// <summary>
        /// CDO实例
        /// </summary>
        public CompositeDataObject CompositeDataObject { get; set; }

        /// <summary>
        /// 所属CDO的主节点的Element.Alias ?? Name
        /// </summary>
        public string CDOColKey { get; set; }

        /// <summary>
        /// 状态机的状态所属的SDO.ID
        /// </summary>
        public string SDOID { get; set; }

        /// <summary>
        /// 业务授权对象ID
        /// </summary>
        public string BPOID { get; set; }

        /// <summary>
        /// 业务授权对象
        /// </summary>
        //Todo:
        // public BizPermissionObject BPO { get; set; }

        /// <summary>
        /// 是否启用状态变更事件
        /// </summary>
        public bool EnableStateChangeEvent { get; set; }

        /// <summary>
        /// SDO实例
        /// </summary>
        public DataObject StaticDataObject { get; set; }

        /// <summary>
        /// 状态列表
        /// </summary>
        public List<TState> States { get; set; }

        /// <summary>
        /// 事件列表
        /// </summary>
        public List<TEvent> Events { get; set; }

        /// <summary>
        /// 状态变换列表
        /// </summary>
        public List<TTransition> Transitions { get; set; }

        /// <summary>
        /// 租户id
        /// </summary>
        public string TenantID { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext1 { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext2 { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext3 { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public override string Creator { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>        
        public override DateTime CreateTime { get; set; }

        /// <summary>
        /// 最后修改人
        /// </summary>
        public override string LastModifier { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>        
        public override DateTime LastModifyTime { get; set; }


        public override object Clone()
        {
            var newObject = this.MemberwiseClone() as StateMachineMetadata;

            if (States != null)
            {
                newObject.States = new List<TState>();
                this.States.ForEach(i => newObject.States.Add(i.Clone() as TState));
            }

            if (Events != null)
            {
                newObject.Events = new List<TEvent>();
                this.Events.ForEach(i => newObject.Events.Add(i.Clone() as TEvent));
            }

            if (Transitions != null)
            {
                newObject.Transitions = new List<TTransition>();
                this.Transitions.ForEach(i => newObject.Transitions.Add(i.Clone() as TTransition));
            }

            return newObject;
        }
    }
}
